import databaseConfig from "./database.json";
import path from "path";

interface IDatabaseConfig {
  host: string;
  dialect: "mysql" | "sqlite" | "postgres" | "mariadb" | "mssql";
  username: string;
  password: string;
  database: string;
}

const configs = {
  development: {
    server: {
      host: "localhost",
      port: 8080,
    },
    database: <IDatabaseConfig>databaseConfig.development,
    jwt: {
      privateKey: "yuins",
    },
    storage: {
      dir: path.resolve(__dirname, "../attachments"),
      prefix: "/public/attachments",
    },
  },
  production: {
    server: {
      host: "localhost",
      port: 8080,
    },
    database: <IDatabaseConfig>databaseConfig.production,
    jwt: {
      privateKey: "yuins",
    },
    storage: {
      dir: path.resolve(__dirname, "../attachments"),
      prefix: "/public/attachments",
    },
  },
};

//  可以根据环境来设置配置，这里我先默认为开发环境
type ENV_TYPE = keyof typeof configs;
const NODE_ENV = <ENV_TYPE>process.env.NODE_ENV || "development";

export default configs[NODE_ENV];
